#include <header.h>

int num = 0;

// 定义一个锁
pthread_mutex_t lock;

void *run(void *arg){
	for (int i = 0; i < 1000000; i++){
		pthread_mutex_lock(&lock);
		num++;
		pthread_mutex_unlock(&lock);
	}
	return NULL;
}


int main(int argc, char* argv[]){

	// 初始化锁,不设置锁的属性
	pthread_mutex_init(&lock, NULL);

	// 初始化
	// pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

	pthread_t son_id;
	pthread_create(&son_id, NULL, run, NULL);

	for (int i = 0; i < 1000000; i++){
		pthread_mutex_lock(&lock);
		num++;
		pthread_mutex_unlock(&lock);
	}

	pthread_join(son_id, NULL);
	printf("%d", num);
	return 0;
}